import time
from time import sleep

from selenium.webdriver.common.by import By

from base.base import Base

url = 'http://192.168.8.222/admin.php'


class Phone1(Base):
    # 获取cookies
    def login(self):
        self.save_cookie('../data/w_warehouse_cookies.json')
        sleep(20)

    # 跳过登录
    def login_admin(self):
        self.set_cookie('../data/w_warehouse_cookies.json')
        self.driver.get(url)
        self.click((By.XPATH, '//*[@id="admin-offcanvas"]/div/ul/li[11]/a'))
        # 点击商品管理，进入iframe
        self.click((By.XPATH, '//*[@id="power-menu-319"]/li[1]/a'))
        self.go_iframe((By.ID, "ifcontent"))

    def phone_foundation(self, phone, announcement, user):
        # 设置手机简洁模式
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[1]/div'))
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[1]/div/div/ul/li[2]'))
        # 客服电话
        self.input((By.XPATH, '/html/body/div[2]/div/form/div[2]/input'), phone)
        # 商城公告
        self.input((By.XPATH, '/html/body/div[2]/div/form/div[3]/textarea'), announcement)
        # 用户中心公告
        self.input((By.XPATH, '/html/body/div[2]/div/form/div[4]/textarea'), user)
        # 保存
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[5]/button'))
        sleep(1)
        print(self.get_text((By.XPATH, '//*[@id="common-prompt"]/p')))
        # //*[@id="common-prompt"]/p
        return self.get_text((By.XPATH, '//*[@id="common-prompt"]/p'))

    def phone_foundation_app(self):
        # App/小程序
        self.click((By.XPATH, '/html/body/div[2]/div/ul/li[2]/a'))
        # 全选是
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[1]/div'))
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[1]/div/div/ul/li[2]'))
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[2]/div'))
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[2]/div/div/ul/li[2]'))
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[3]/div'))
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[3]/div/div/ul/li[2]'))
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[4]/div'))
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[4]/div/div/ul/li[2]'))
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[5]/div'))
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[5]/div/div/ul/li[2]'))
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[6]/div'))
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[6]/div/div/ul/li[2]'))
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[7]/div'))
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[7]/div/div/ul/li[2]'))
        # 点击保存
        self.click((By.XPATH, '/html/body/div[2]/div/form/div[8]/button'))
        print(self.get_text((By.XPATH, '//*[@id="common-prompt"]/p')))
        return self.get_text((By.XPATH, '//*[@id="common-prompt"]/p'))


if __name__ == '__main__':
    p = Phone1()
    p.login_admin()
    p.phone_foundation('1234567890', 'jkhahlfauhfhuifuhafhauhoi', 'uffgiaifuiafuhahfuaufhli')
    p.phone_foundation_app()
